public class Thread01 {
    public static void main(String[] args) {
        MyThread1 t1 = new MyThread1();
        MyThread1 t2 = new MyThread1();
        t1.start();
        t1.setName("线程1");
        t2.start();
        t2.setName("线程2");

    }


    static class MyThread1 extends Thread {
        //final Object obj = new Object();
        static int n = 1;

        @Override
        public void run() {
            while (n <= 100) {
                synchronized (Object.class) {
                    Object.class.notify();
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "打印" + n);

                    n++;
                    try {
                        Object.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
